package com.party.business.controller;


import java.util.Arrays;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.party.common.annotation.DataSource;
import com.party.common.annotation.Log;
import com.party.common.core.controller.BaseController;
import com.party.common.core.domain.AjaxResult;
import com.party.common.core.page.TableDataInfo;
import com.party.common.enums.BusinessType;
import com.party.common.enums.DataSourceType;
import com.party.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.party.business.domain.TheoreticalDoctrine;
import com.party.business.service.ITheoreticalDoctrineService;

/**
 * 理论法规Controller
 *
 * @author ruoyi
 * @date 2025-06-24
 */
@RestController
@RequestMapping("/business/doctrine")
public class TheoreticalDoctrineController extends BaseController {
    @Autowired
    private ITheoreticalDoctrineService theoreticalDoctrineService;

    /**
     * 查询理论法规列表
     */
//@RequiresPermissions("business:doctrine:list")
    @GetMapping("/list")
    @DataSource(value = DataSourceType.SLAVE)
    public TableDataInfo list(TheoreticalDoctrine theoreticalDoctrine) {
        startPage();
        List<TheoreticalDoctrine> list = theoreticalDoctrineService.selectTheoreticalDoctrineList(theoreticalDoctrine);
        return getDataTable(list);
    }

    /**
     * 导出理论法规列表
     */
    //@RequiresPermissions("business:doctrine:export")
    @Log(title = "理论法规", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TheoreticalDoctrine theoreticalDoctrine) {
        List<TheoreticalDoctrine> list = theoreticalDoctrineService.selectTheoreticalDoctrineList(theoreticalDoctrine);
        ExcelUtil<TheoreticalDoctrine> util = new ExcelUtil<TheoreticalDoctrine>(TheoreticalDoctrine.class);
        util.exportExcel(response, list, "理论法规数据");
    }

    /**
     * 获取理论法规详细信息
     */
    //@RequiresPermissions("business:doctrine:query")
    @GetMapping(value = "/{id}")
    @DataSource(value = DataSourceType.SLAVE)
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(theoreticalDoctrineService.selectTheoreticalDoctrineById(id));
    }

    /**
     * 新增理论法规
     */
    //@RequiresPermissions("business:doctrine:add")
    @Log(title = "理论法规", businessType = BusinessType.INSERT)
    @PostMapping
    @DataSource(value = DataSourceType.SLAVE)
    public AjaxResult add(@RequestBody TheoreticalDoctrine theoreticalDoctrine) {
        return toAjax(theoreticalDoctrineService.insertTheoreticalDoctrine(theoreticalDoctrine));
    }

    /**
     * 修改理论法规
     */
    //@RequiresPermissions("business:doctrine:edit")
    @Log(title = "理论法规", businessType = BusinessType.UPDATE)
    @PutMapping
    @DataSource(value = DataSourceType.SLAVE)
    public AjaxResult edit(@RequestBody TheoreticalDoctrine theoreticalDoctrine) {
        return toAjax(theoreticalDoctrineService.updateTheoreticalDoctrine(theoreticalDoctrine));
    }

    /**
     * 删除理论法规
     */
    //@RequiresPermissions("business:doctrine:remove")
    @Log(title = "理论法规", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @DataSource(value = DataSourceType.SLAVE)
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(theoreticalDoctrineService.removeByIds(Arrays.asList(ids)));
    }
}
